package com.shinewind.common.config.alipay.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.shinewind.common.config.alipay.properties.AliPayProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
@ConditionalOnProperty(value = "alipay.enable",havingValue = "true")
public class AliPayConfiguration {
    @Autowired
    private AliPayProperties aliPayProperties;

    @Bean
    public AlipayClient getAlipayClient(){
        //初始化AlipayClient对象
        AlipayClient alipayClient = new DefaultAlipayClient(aliPayProperties.getGatewayUrl(),
                aliPayProperties.getApp_id(), aliPayProperties.getMerchant_private_key(),
                aliPayProperties.getFormat() ,aliPayProperties.getCharset(),
                aliPayProperties.getAlipay_public_key(),aliPayProperties.getSign_type());
        return alipayClient;
    }

    @Bean
    public AlipayTradePagePayRequest getPayRequest(){
        //设置请求参数
        AlipayTradePagePayRequest payRequest = new AlipayTradePagePayRequest();
        return payRequest;
    }
}
